package com.uinnova.springboot.demo.swagger;

import com.uinnova.springboot.demo.common.Groups;
import com.uinnova.springboot.demo.kit.Retkit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀钦
 * @date 2018-12-28-00:01
 * ${DES}
 */
@RestController
@Api
@Validated
public class SwaggerController {

    /**
     * @author 张攀钦
     * @date 2018/12/29-23:55
     * jQuery.ajax ({
     * url: myurl,
     * type: "POST",
     * data: JSON.stringify({data:"test"}),
     * dataType: "json",
     * contentType: "application/json;charset=utf-8",
     * success: function(){
     * //
     * }
     * });
     */

    @PostMapping(value = "/jail/swagger")
    public Retkit<Swagger> test(@Validated(value = {Groups.Update.class}) @RequestBody Swagger swagger) {
        return Retkit.ok(swagger);
    }

    @GetMapping(value = "/jail/swagger/bean")
    public Retkit<Swagger> testBean(@Validated(value = {Groups.Insert.class}) Swagger swagger) {
        return Retkit.ok(swagger);
    }

    @GetMapping("/jail/swagger/{id}")
    @ApiOperation(value = "ceshiRestful", notes = "参数在url中", httpMethod = "GET")
    public Retkit<String> testPathVariable(@PathVariable String id) {
        return Retkit.ok(id);
    }
    @PostMapping("/jail/swagger/param1")
    @ApiOperation(value = "测试表单", notes = "参数为lists=111&lists=2222或者lists=124124,13213", httpMethod = "POST")
    public Retkit<List<String>> testParamPost(@RequestParam List<String> lists, String name) {
        return Retkit.ok(lists);
    }

}
